package com.feng.aclservice.controller;


import com.feng.aclservice.entity.Permission;
import com.feng.aclservice.service.AclPermissionService;
import com.feng.commonutils.R;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 权限 前端控制器
 * </p>
 *
 * @author fengge
 * @since 2023-04-02
 */
@RestController
@RequestMapping("/aclservice/acl-permission")
@CrossOrigin
public class AclPermissionController {
    @Autowired
    private AclPermissionService aclPermissionService;
    //获取全部菜单
    @ApiOperation(value = "查询所有菜单")
    @GetMapping
    public R indexAllPermission() {
        return   aclPermissionService.queryAllMenuGuli();

    }
    @DeleteMapping("remove/{id}")
    public R remove(@PathVariable String id){
        return aclPermissionService.removeChildrenByid(id);
    }
    @PostMapping("/doAssign")
    public R doAssign(String roleId,String[] permissionId) {
      return   aclPermissionService.saveRolePermissionRealtionShipGuli(roleId,permissionId);

    }
    @ApiOperation(value = "根据角色获取菜单")
    @GetMapping("toAssign/{roleId}")
    public R toAssign(@PathVariable String roleId) {
        List<Permission> list = aclPermissionService.selectAllMenu(roleId);
        return R.ok().data("children", list);
    }
    @ApiOperation(value = "新增菜单")
    @PostMapping("save")
    public R save(@RequestBody Permission permission) {
        aclPermissionService.save(permission);
        return R.ok();
    }

    @ApiOperation(value = "修改菜单")
    @PutMapping("update")
    public R updateById(@RequestBody Permission permission) {
        aclPermissionService.updateById(permission);
        return R.ok();
    }




}

